package com.ott.tool;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

import org.json.JSONObject;

import com.ott.Util.MtsHttpClient;
import com.ott.Util.SortEncryptUtil;

public class ReportInfo {

	public static void reportMts(String url){
		//上报云端
		try {
			String check_name = "bestv";
			String check_code = "hfu6554uty53hyed8t512g9";
			String noncestr = UUID.randomUUID().toString().replace("-", "").substring(0, 8);
			IndexForm.textArea.append("获取上报影吧编号\r\n\r\n");
			String timestamp = String.valueOf(System.currentTimeMillis());
			String cinema_code = JDBCHelp.findCinemaCode();
			IndexForm.textArea.append("上报影吧编号="+cinema_code+"\r\n\r\n");
			Map<String, String> paramMap = new HashMap<String, String>();
	        paramMap.put("cinema_code", cinema_code);
	        paramMap.put("errcode", "0");
	        paramMap.put("errmsg", "success");
	        paramMap.put("feedback_flag", "1");
	        paramMap.put("noncestr", noncestr);
	        paramMap.put("timestamp", timestamp);
	        paramMap.put("task_id","VU001");	
	        String sign = SortEncryptUtil.getMD5SortSign(paramMap);
			
			JSONObject json = new JSONObject();
			json.put("check_name", check_name);
			json.put("check_code", check_code);
			json.put("cinema_code", cinema_code);
			json.put("feedback_flag","1");
			json.put("errcode","0");
			json.put("task_id","VU001");	
			json.put("errmsg", "success");
			json.put("noncestr", noncestr);
			json.put("timestamp", timestamp);
			json.put("sign", sign);
			IndexForm.textArea.append("上报信息："+json.toString()+"\r\n\r\n");
			IndexForm.textArea.append("开始上报\r\n\r\n");
			IndexForm.textArea.append("等待返回结果\r\n\r\n");
			String data = MtsHttpClient.post(url, json.toString());
			IndexForm.textArea.append("返回结果="+data+"\r\n\r\n");
			if (data.equals("success")) {
				IndexForm.textArea.append("上报成功\r\n");
			}else{
				IndexForm.textArea.append("上报失败\r\n");
			}
		} catch (Exception e) {
			IndexForm.textArea.append("上报失败\r\n");
		}
		
	}
	
	public static void main(String[] args) {
		String url = "http://192.168.1.242:8082/mts/versionUpdate/feedback.json";
		ReportInfo.reportMts(url);
	}
}
